package com.yan_jiu_sheng.LeetCodeHot100.AC;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/move-zeroes/description/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 * 双指针
 *
 * @author yulongTian
 * @create 2024-05-24 16:32
 */
public class Test04 {

    public static void main(String[] args) {
//        int[] nums = new int[]{1,0, 1, 0, 3, 12};
        int[] nums = new int[]{0, 0};
        new Test04().moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }

    public void moveZeroes(int[] nums) {
        int leftPoint = 0;
        int rightPoint = 0;
        while (leftPoint < nums.length) {
            if (nums[leftPoint] != 0) {
                leftPoint++;
                continue;
            }
            // nums[leftPoint] = 0
            rightPoint = leftPoint;
            while (rightPoint < nums.length) {
                if (nums[rightPoint] != 0) {
                    nums[leftPoint] = nums[rightPoint];
                    nums[rightPoint] = 0;
                    break;
                }
                rightPoint++;
            }
            leftPoint++;
        }


    }
}
